package com.example.wechat.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.wechat.R;
import com.example.wechat.adapter.FavoritesLinkAdapter;
import com.example.wechat.model.FavoriteLink;

import java.util.ArrayList;
import java.util.List;

public class FavoritesLinkFragment extends Fragment {
    private RecyclerView recyclerView;
    private FavoritesLinkAdapter adapter;
    private List<FavoriteLink> favoriteLinks;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_favorites_link, container, false);
        
        recyclerView = view.findViewById(R.id.link_recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        
        favoriteLinks = new ArrayList<>();
        adapter = new FavoritesLinkAdapter(favoriteLinks);
        recyclerView.setAdapter(adapter);
        
        loadFavoriteLinks();
        
        return view;
    }

    private void loadFavoriteLinks() {
        // TODO: 从数据库或服务器加载收藏的链接
        // 这里添加一些测试数据
        favoriteLinks.add(new FavoriteLink("微信官方网站", "https://www.wechat.com", System.currentTimeMillis()));
        favoriteLinks.add(new FavoriteLink("微信开发者文档", "https://developers.weixin.qq.com", System.currentTimeMillis()));
        adapter.notifyDataSetChanged();
    }
} 